<script setup lang="ts">
import { onHide, onLaunch, onShow } from '@dcloudio/uni-app'
import { useAppStore, useUserStore } from './stores'
import { submitError } from './apis'

const appStore = useAppStore()
const userStore = useUserStore()

uni.onError((error: any) => {
  console.error('捕获错误: ', error)
  if (process.env.NODE_ENV === 'production') {
    submitError({
      message: error?.stack?.slice(0, 1024),
      clientType: 'miniapp-teacher',
      submitUser: userStore?.userInfo?.id,
    }).catch((submitError) => {
      console.warn('异常日志上报出错: ', submitError)
    })
  }
})

onLaunch(() => {
  appStore.loadDict()
  appStore.updateApp()
  if (userStore.token) {
    userStore.refreshUserInfo()
  }
})
onShow(() => {
})
onHide(() => {
})
</script>

<style lang="scss">

</style>
